package com.ljm.commom.web.conf;

import com.ljm.commom.web.filter.BodyReaderRequestFilter;
import com.ljm.commom.web.filter.CustomCorsFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

/**
 * @author ChenHuaMing
 * 版权：    Copyright by ljm
 * 描述：    web通用拦截器配置
 * 修改人：  HuamingChen
 * 修改时间：2020/3/6
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */

@Configuration
public class FilterConf {
    @Bean
    public FilterRegistrationBean<BodyReaderRequestFilter> bodyReaderRequestFilter() {
        FilterRegistrationBean<BodyReaderRequestFilter> bodyReaderRequestFilterBean = new FilterRegistrationBean<>();
        bodyReaderRequestFilterBean.setFilter(new BodyReaderRequestFilter());
        bodyReaderRequestFilterBean.addUrlPatterns("/*");
        bodyReaderRequestFilterBean.setName("bodyReaderRequestFilter");
        bodyReaderRequestFilterBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return bodyReaderRequestFilterBean;
    }

    @Bean
    public FilterRegistrationBean<CustomCorsFilter> customCorsFilter() {
        FilterRegistrationBean<CustomCorsFilter> bodyReaderRequestFilterBean = new FilterRegistrationBean<>();
        bodyReaderRequestFilterBean.setFilter(new CustomCorsFilter());
        bodyReaderRequestFilterBean.addUrlPatterns("/*");
        bodyReaderRequestFilterBean.setName("customCorsFilter");
        bodyReaderRequestFilterBean.setOrder(Ordered.HIGHEST_PRECEDENCE+1);
        return bodyReaderRequestFilterBean;
    }
}
